package cn.sunshuai.service.impl;

import cn.sunshuai.domain.Movie;
import cn.sunshuai.domain.MovieUser;
import cn.sunshuai.exception.BusinessException;
import cn.sunshuai.mapper.MovieMapper;
import cn.sunshuai.service.IMovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MovieServiceImpl implements IMovieService {
    @Autowired
    private MovieMapper movieMapper;

    @Override
    public List<Movie> findAll() {
        return movieMapper.loadAll();
    }

    @Override
    public Movie movieBuy(Long id) {
        Movie movie = movieMapper.loadByiId(id);
        if(movie.getStock()<=0){
            throw new BusinessException("电影票已售馨!");
        }
        return movie;
    }

    @Override
    public void add(MovieUser movieUser) {
        movieMapper.add(movieUser);
    }

    @Override
    public void update(MovieUser movieUser) {
        movieMapper.update(movieUser);
    }

    @Override
    public void addMovie(Movie movie) {
        movieMapper.addMovie( movie);
    }

    @Override
    public void updateMovie(Movie movie) {
        movieMapper.updateMovie(movie);
    }

    @Override
    public MovieUser findByMovieId(Long id) {
        return movieMapper.findByMovieId(id);
    }

}
